using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using ACS.Debugger.Core.Impl;

namespace ACS.Debugger.Core.NativeMethods
{
    public interface IComConstants
    {
        string ClassGUID
        {
            get;
        }

        string InterfaceGUID
        {
            get;
        }
    }

    public class ComInterfaces
    {

        public static ComInterfaces Instace = new ComInterfaces();
    
        [DllImport("ole32.Dll")]
        public static extern uint CoCreateInstance(ref Guid clsid,
                                                   [MarshalAs(UnmanagedType.IUnknown)] object inner,
                                                   uint context,
                                                   ref Guid uuid,
                                                   [MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject);
   
        public static T CreateObject<T>()
        {
            const uint CLSCTX_INPROC_SERVER = 1;

            Guid comInterface = new Guid("00000000-0000-0000-C000-000000000046");
            Guid comClass = typeof(T).GUID;

            object outInstance;

            uint u = CoCreateInstance(
                ref comClass,
                null,
                CLSCTX_INPROC_SERVER,
                ref comInterface,
                out outInstance);


            return (T)outInstance;
        }
    }
}